home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / NasheKino (RU).ifs < prev    next >
Encoding:
Text File  |  2004-03-20  |  6.7 KB  |  237 lines

  1. // GETINFO SCRIPTING
  2. // Imports russian movies info from NasheKino
  3.  
  4. (***************************************************
  5.  *  Movie information import script for:           *
  6.  *    NasheKino Russian,                           *
  7.  *    http://www.nashekino.ru/                     *
  8.  *                                                 *
  9.  *  (c) 2002 Yan Sorkin       ysorkin@mail.ru      *
  10.  *                                                 *
  11.  *  Known issues:                                  *
  12.  *  - Movie length not supported                   *
  13.  *                                                 *
  14.  *  For use with Ant Movie Catalog 3.4.0           *
  15.  *  www.antp.be/software/moviecatalog              *
  16.  *                                                 *
  17.  *  This program is free software; you can         *
  18.  *  redistribute it and/or modify it under the     *
  19.  *  terms of the GNU General Public License as     *
  20.  *  published by the Free Software Foundation;     *
  21.  *  either version 2 of the License, or (at your   *
  22.  *  option) any later version.                     *
  23.  ***************************************************)
  24.  
  25. program NasheKino;
  26. const
  27.   BaseAddress = 'http://www.nashekino.ru/';
  28. //  BaseAddress = 'http://localhost/';
  29. var
  30.   MovieName: string;
  31.  
  32. function GetTextBlockFrom(Text: string; StartAt: string): string;
  33. var
  34.   TextBlock: string;
  35.   StartPos, EndPos: Integer;
  36. begin
  37.   TextBlock := Text;
  38.   StartPos := pos(StartAt, TextBlock);
  39.   if StartPos > 0 then
  40.   begin
  41.     Delete(TextBlock, 1, StartPos - 1);
  42.     result := TextBlock;
  43.   end;
  44. end;
  45.  
  46. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  47. var
  48.   i: Integer;
  49. begin
  50.   result := -1;
  51.   if StartAt < 0 then
  52.     StartAt := 0;
  53.   for i := StartAt to List.Count-1 do
  54.     if Pos(Pattern, List.GetString(i)) <> 0 then
  55.     begin
  56.       result := i;
  57.       Break;
  58.     end;
  59. end;
  60.  
  61. procedure AnalyzePage(Address: string);
  62. var
  63.   Page: TStringList;
  64.   LineNr: Integer;
  65.   Line: string;
  66.   TextBlock: string;
  67. begin
  68.   Page := TStringList.Create;
  69.   Page.Text := GetPage(Address);
  70.   if pos('═α°σ ΩΦφε /∩εΦ±Ω/', Page.Text) = 0 then
  71.   begin
  72.     SetField(fieldURL, Address);
  73.     AnalyzeMoviePage(Page);
  74.   end else
  75.   if pos('╧ε τα∩≡ε±≤ "', Page.Text) = 0 then
  76.   begin
  77.     ShowMessage('No movies found');
  78.   end else
  79.   begin
  80.     PickTreeClear;
  81.     LineNr := FindLine('<hr width="100%" size=1 color="black">', Page, 0);
  82.     if LineNr > -1 then
  83.     begin
  84.       PickTreeAdd('Movies', '');
  85.       AddMoviesTitles(Page, LineNr);
  86.     end;
  87.     if PickTreeExec(Address) then
  88.       AnalyzePage(Address);
  89.   end;
  90.   Page.Free;
  91. end;
  92.  
  93. procedure AnalyzeMoviePage(Page: TStringList);
  94. var
  95.   Value, PageText, Text: string;
  96.   LineNr, MovieLength: Integer;
  97.   BeginPos, EndPos: Integer;
  98. begin
  99.  
  100.   // All the info is in one line
  101.   PageText := GetTextBlockFrom( Page.Text, '<a name=0 class=ab12b>' );
  102.   EndPos := pos('├Σσ Γετ∞εµφε ∩≡Φεß≡σ≥σφΦσ Σαφφεπε ⌠Φδⁿ∞α', PageText);
  103.   if EndPos > 0 then
  104.   begin
  105.     PageText := copy( PageText, 1, EndPos - 1 );
  106.   end;
  107.  
  108.   if Length(PageText) > 0 then
  109.   begin
  110.     // Original Title
  111.     BeginPos := 1;
  112.     EndPos := pos('</a>', PageText);
  113.     Value := copy(PageText, BeginPos, EndPos - BeginPos);
  114.     HTMLDecode(Value);
  115.     HTMLRemoveTags(Value);
  116.     SetField(fieldOriginalTitle, Value);
  117.     Delete(PageText, 1, EndPos - 1);
  118.     
  119.     // Alternative titles (skip)
  120.     BeginPos := pos('Σ≡≤πΦσ φατΓαφΦ :', PageText);
  121.     if BeginPos > 0 then Delete(PageText, 1, BeginPos - 1);
  122.  
  123.     // Year
  124.     BeginPos := pos('ab10>, ', PageText) + 7;
  125.     EndPos := pos('πεΣ.', PageText) - 1;
  126.     if EndPos > BeginPos then
  127.     begin
  128.         Value := copy(PageText, BeginPos, EndPos - BeginPos);
  129.         SetField(fieldYear, Value);
  130.         Delete(PageText, 1, EndPos - 1);
  131.     end;
  132.     
  133.     // Length
  134.     BeginPos := pos('πεΣ., ', PageText) + 6;
  135.     EndPos := pos('∞Φφ.', PageText) - 1;
  136.     if EndPos > BeginPos then
  137.     begin
  138.         Value := copy(PageText, BeginPos, EndPos - BeginPos);
  139.         SetField(fieldLength, Value);
  140.         Delete(PageText, 1, EndPos - 1);
  141.     end;
  142.   end;
  143.  
  144.   // Director
  145.   Text := GetTextBlockFrom( PageText, '╨σµΦ±±σ≡(√): ' );
  146.   if Length(Text) > 0 then
  147.   begin
  148.     BeginPos := 14;
  149.     EndPos := pos('<br>', Text);
  150.     if EndPos > BeginPos then
  151.     begin
  152.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  153.       HTMLDecode(Value);
  154.       HTMLRemoveTags(Value);
  155.       SetField(fieldDirector, Value);
  156.     end;
  157.   end;
  158.  
  159.   // Actors
  160.   Text := GetTextBlockFrom( PageText, '└Ω≥σ≡(√): ' );
  161.   if Length(Text) > 0 then
  162.   begin
  163.     BeginPos := 11;
  164.     EndPos := pos('<br>', Text);
  165.     if EndPos > BeginPos then
  166.     begin
  167.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  168.       HTMLDecode(Value);
  169.       HTMLRemoveTags(Value);
  170.       SetField(fieldActors, Value);
  171.     end;
  172.   end;
  173.  
  174.   // Description
  175.   Text := GetTextBlockFrom( PageText, '╬ ⌠Φδⁿ∞σ:' );
  176.   if Length(Text) > 0 then
  177.   begin
  178.     BeginPos := pos('<a class=ab10> ', Text) + 15;
  179.     EndPos := pos('<hr', Text);
  180.     if EndPos > BeginPos then
  181.     begin
  182.       Value := copy(Text, BeginPos, EndPos - BeginPos);
  183.       HTMLDecode(Value);
  184.       Value := StringReplace(Value, '<br>', #13#10);
  185.       Value := StringReplace(Value, '<p', #13#10#13#10 + '<p');
  186.       HTMLRemoveTags(Value);
  187.       SetField(fieldDescription, Value);
  188.     end;
  189.   end;
  190.  
  191.   DisplayResults;
  192. end;
  193.  
  194. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  195. var
  196.   Line: string;
  197.   MovieTitle, MovieAddress, AddrPrefix: string;
  198.   StartPos, EndPos: Integer;
  199. begin
  200.   repeat
  201.     LineNr := LineNr + 1;
  202.     Line := Page.GetString(LineNr);
  203.     StartPos := pos('showfilm.cgi', Line);
  204.     AddrPrefix := 'cgi-bin/';
  205.     if StartPos = 0 then
  206.     begin
  207.       StartPos := pos('data/films', Line);
  208.       AddrPrefix := '';
  209.     end;
  210.     EndPos := pos('</div>', Line);
  211.     if (StartPos > 0) and (EndPos = 0) then
  212.     begin
  213.       MovieAddress := copy(Line, StartPos, pos('">', Line) - StartPos);
  214.       MovieTitle := Line;
  215.       HTMLDecode(Movietitle);
  216.       HTMLRemoveTags(MovieTitle);
  217.       PickTreeAdd(MovieTitle, BaseAddress + AddrPrefix + MovieAddress);
  218.     end;
  219.   until EndPos > 0;
  220. end;
  221.  
  222. begin
  223.   if CheckVersion(3,4,0) then
  224.   begin
  225.     MovieName := GetField(fieldOriginalTitle);
  226.     if MovieName = '' then
  227.       MovieName := GetField(fieldTranslatedTitle);
  228.     if Input('Import from NasheKino', 'Enter the title of the movie:', MovieName) then
  229.     begin
  230.       AnalyzePage('http://www.nashekino.ru/cgi-bin/find.cgi?t=0&sval='+UrlEncode(MovieName));
  231. //      AnalyzePage('http://localhost/search1.htm');
  232.     end;
  233.   end else
  234.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  235. end.
  236.  
  237.